package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlDmIndexDimtbService;
import com.dw.etl.core.mapper.EtlDmIndexDimtbMapper;
import com.dw.etl.core.bean.model.EtlDmIndexDimtb;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * etlDmIndexDimtb服务实现类
 * Created by hozeData on 2021/06/23.
 */
@Service
@Transactional
public class EtlDmIndexDimtbServiceImpl implements EtlDmIndexDimtbService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlDmIndexDimtbServiceImpl.class);

    @Autowired
    private EtlDmIndexDimtbMapper etlDmIndexDimtbMapper;

    @Override
    public int insert(EtlDmIndexDimtb etlDmIndexDimtb) {
        if(StringUtils.isEmpty(etlDmIndexDimtb.getPk())){
            String uuid32 = UUIDUtil.getUUID32();
            etlDmIndexDimtb.setPk(uuid32);
        }
        return etlDmIndexDimtbMapper.insert(etlDmIndexDimtb);
    }

    @Override
    public int insertSelective(EtlDmIndexDimtb etlDmIndexDimtb)  {
        if(StringUtils.isEmpty(etlDmIndexDimtb.getPk())){
            String uuid32 = UUIDUtil.getUUID32();
            etlDmIndexDimtb.setPk(uuid32);
        }
        return etlDmIndexDimtbMapper.insertSelective(etlDmIndexDimtb);
    }

    @Override
    public int deleteById(String pk)  {
        return etlDmIndexDimtbMapper.deleteByPrimaryKey(pk);
    }

    @Override
    public int updateByIdSelective(EtlDmIndexDimtb etlDmIndexDimtb)  {

        return etlDmIndexDimtbMapper.updateByPrimaryKeySelective(etlDmIndexDimtb);
    }

    @Override
    public int updateById(EtlDmIndexDimtb etlDmIndexDimtb)  {
        return etlDmIndexDimtbMapper.updateByPrimaryKey(etlDmIndexDimtb);
    }

    @Override
    public EtlDmIndexDimtb getById(String pk)  {
        return etlDmIndexDimtbMapper.selectByPrimaryKey(pk);
    }

    @Override
    public List<EtlDmIndexDimtb> findByModel(EtlDmIndexDimtb etlDmIndexDimtb)  {
        return etlDmIndexDimtbMapper.findByModel(etlDmIndexDimtb);
    }

    @Override
    public PaginationVO<EtlDmIndexDimtb> findPageByModel(EtlDmIndexDimtb etlDmIndexDimtb, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlDmIndexDimtb> quesList = etlDmIndexDimtbMapper.findByModel(etlDmIndexDimtb);
        PageInfo<EtlDmIndexDimtb> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlDmIndexDimtb> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
